	function showPlanResWindow(obj){
		var rows = $("#addPlanResource-datagrid").datagrid('getRows');
		var rowIndex = 0;
		if(rows !=null){
			rowIndex = rows.length;
		}
		var url = $(obj).attr("url")+"?orderNum="+rowIndex+"&planType=1";
		var titleName = $(obj).attr("title");
		var _width=($(obj).attr("win-width")==undefined)?"96%":$(obj).attr("win-width");
		var _height=($(obj).attr("win-height")==undefined)?"96%":$(obj).attr("win-height");
		var _customerClass=($(obj).attr("customer-id")==undefined)?"customer-id":$(obj).attr("customer-id");
		$("<div/>").addClass("customer-dialog "+_customerClass).window({
			width :_width,
			height :_height,
			modal : true,
			minimizable : false,
			resizable : false,
			title : titleName,
			border : false,
			onClose : function() {
				$(this).window('destroy');
			},
			href : url
		});
	}
	function actionOp(value,row,index){
		var html="";
		html +="<a href='javascript:void(0)' onclick='downRow("+index+")'  title='下移' class='btn btn-xs btn-success mar5'><i class='iconfont icon-xiayi'></i>下移</a>";
		html +="<a href='javascript:void(0)' onclick='upRow("+index+")' title='上移' class='btn btn-xs btn-success mar5'><i class='iconfont icon-shangyi'></i>上移</a>";
		/*html+= "<a href='javascript:void(0)' onclick='showPlanResWindow(this);' win-height='70%' win-width='760' url='/video/plan/res/"+row.resourceId+"/edit' title='编辑' class='btn btn-xs btn-warning window_bt mar5'><i class='icon-edit'></i></a>";
		*/html+="<a href='javascript:void(0)'  onclick='deleteRow(\""+row.resourceUuid+"\","+index+")' title='删除' class='btn btn-xs btn-danger mar5'><i class='iconfont icon-shanchu'></i>删除</a>";
		return html;
	}

	function upRow(index){
		var rows = $("#addPlanResource-datagrid").datagrid('getRows');
		var rowLength = rows.length;
		if(index == 0){
			layer.alert("顶行无法上移！",{
				icon : 1,
				skin : "layer-ext-moon",
			 }, function(index1) {
				 layer.close(index1);
			 });
		}else{
			var row = rows[index];
			$("#addPlanResource-datagrid").datagrid("deleteRow",index);
			index--;
			$("#addPlanResource-datagrid").datagrid("insertRow",{
				index:index,
				row:row
			});
		}
		$("#addPlanResource-datagrid").datagrid("loadData",$("#addPlanResource-datagrid").datagrid("getData"));
		//$("#addPlanResource-datagrid").datagrid("selectRow",index);
	}
	
	function downRow(index){
		var rows = $("#addPlanResource-datagrid").datagrid('getRows');
		var rowLength = rows.length;
		if(index == rowLength-1){
			 layer.alert("底行无法下移！",{
				icon : 1,
				skin : "layer-ext-moon",
			 }, function(index1) {
				 layer.close(index1);
			 });
		}else{
			var row = rows[index];
			$("#addPlanResource-datagrid").datagrid("deleteRow",index);
			index++;
			$("#addPlanResource-datagrid").datagrid("insertRow",{
				index:index,
				row:row
			});
		}
		$("#addPlanResource-datagrid").datagrid("loadData",$("#addPlanResource-datagrid").datagrid("getData"));
	} 
	
	function deleteRow(id,index){
		layer.confirm('是否执行此操作？', {
			icon : 3,
			btn : [ '确认', '取消' ]
		}, function(index1) {
			layer.close(index1); 
	   		var row = $("#addPlanResource-datagrid").datagrid("deleteRow",index);
	   		$("#addPlanResource-datagrid").datagrid("loadData",$("#addPlanResource-datagrid").datagrid("getData"));
	    },function(index1){
	    	layer.close(index1); 
	    });
	}
	function getResources(){
		var rows = $("#addPlanResource-datagrid").datagrid('getRows');
		if(rows.length>0){
			return JSON.stringify(rows);
		}
		return "";
	}
	
	function getStartTime(){
		var startTime ="";
	 
		var start_type = $("#selTriggerTime").combobox("getValue");
		var minute = $("#minute").numberspinner("getValue");
		var hour =  $("#hour").numberspinner("getValue");
		if(start_type == "day"){
			startTime = "0 "+minute+" "+hour+" * * ?";
		}else if(start_type == "week"){
			var week = $("#week").combobox("getValue");
			startTime = "0 "+minute+" "+hour+" ? * "+week;
		}else if(start_type == "month"){
			var day = $("#day").numberspinner("getValue");
			startTime = "0 "+minute+" "+hour+" "+day+" *  ?";
		}
		return startTime;
	}
	 
	function savePlan(obj){
		var $form = $(obj).parents("form");
		var $url = $form.attr("action");
		 
		if (!$form.form("validate")) {// 验证没通过，返回
			return false;
		}
		var params = {};
		var resources = getResources();
		var startTime ="";
		if($("#playType").combobox("getValue")==2){
			 startTime = getStartTime();
		}
		if(resources ==""){
			layer.alert("至少选择一个要有一个视频资源",{
				icon : 1,
				skin : "layer-ext-moon",
			},function(index) {
				layer.close(index);
				$("#planTab").tabs("select",1);
			});
			return false;
		}
		params.resouerces = resources;
		params.startTime = startTime;
		golbal.progress();
		$form.ajaxSubmit({
			url :$url,  
			type : 'POST',
			dataType : 'json',
		    data:params,
		    success : function(msg) {
				$.messager.progress("close");
				if (msg.success == 1) {
					layer.alert(msg.msg || "添加成功！", {
						icon : 1,
						skin : "layer-ext-moon",
					}, function(index) {
						layer.close(index);
						closeDialog(obj);
						$(".easyui-datagrid").datagrid("reload");
						$(".easyui-treegrid").treegrid("reload");
					});
				} else {
					layer.alert(msg.msg || "添加失败！请稍候重试", {
						icon : 2,
						skin : "layer-ext-moon",
					}, function(index) {
						layer.close(index);
						if (msg.o != undefined && $backUrl) {
							window.location.href = $backUrl;
						}
					});
				}
			},
			error : function(x, s, error) {
				$.messager.progress("close");
				layer.alert("添加失败！服务器出错：" + error + ";错误代码：" + x.status, {
					icon : 2,
					skin : "layer-ext-moon",
				});
			} 
		 });
		return false;
	}